package com.yc.navy.springmvc.listener;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.yc.navy.springmvc.util.ConstantIfo;
import com.yc.navy.springmvc.util.StringUtil;


;

@WebListener
public class CreateUploadPathListener implements ServletContextListener{
	
	public void contextInitialized(ServletContextEvent sce) {
		String path = sce.getServletContext().getInitParameter("uploadpath");
		if(StringUtil.checkNull(path)) {
			path = ConstantIfo.UPLOADPATH;
		}
		
		String basepath = sce.getServletContext().getRealPath("/");	//获取项目部署在服务中的绝对路径
		ConstantIfo.contextPath = basepath;
		File parent = new File(basepath).getParentFile();
		File f1 = new File(parent, path);
		if(!f1.exists()) {
			f1.mkdirs();
		}
		ConstantIfo.UPLOADPATH = path;
		ConstantIfo.BASEPATH = basepath;
		ConstantIfo.SERVERPATH = parent.getAbsolutePath();
	}
}
